<?php
namespace app\appin\service;

class Request
{
    protected $app;

    public $uri = '';

    public function __construct()
    {
        $this->app = app();
    }

    /**
     * [uri 获取当前访问的URI]
     * @return [type] [description]
     */
    public function uri()
    {
        $appinName          = $this->app->appin['name'];
        $appinController    = strtolower( $this->app->appin['controller'] );
        $appinAction        = $this->app->appin['action'];
        $this->uri = implode('-', compact('appinName', 'appinController', 'appinAction'));
        return $this->uri;
    }

    /**
     * [menus 获取当前访问的插件的所有系统菜单]
     * @param  array  $systemMenus [description]
     * @return [type]              [description]
     */
    public function menus($systemMenu = [])
    {
        if ( empty($systemMenu) ) {
            $systemMenu = $this->app->appinConfig['system_menu'];
        }
        static $menus = [];
        foreach( $systemMenu as $menu) {
            $menus[] = $menu['id'];
            if (isset($menu['son']) && count($menu['son']) > 0) {
                $this->menus($menu['son']);
            }
        }
        return $menus;
    }

    /**
     * [hasAuther 判断是否需要鉴权]
     * @return boolean [description]
     */
    public function hasAuther()
    {
        return in_array($this->uri(), $this->menus());
    }
}
